package com.ktjiaoyu.crm.repository;

import com.ktjiaoyu.crm.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserRepository<ionExecutor> extends JpaRepository<User,Long> {

    public List<User> findByUsrName(String usrName);

    List<User> findByUsrNameLike(String s);

    public Long countByUsrName(String usrName);

//    @Query("select u from User u where u.usrRoleId=?1")
//    public List<User>findByRoleId(Long roleId);
    @Query(value = "select *from sys_user where usr_role_id=?1",nativeQuery = true)
    public List<User>findByRoleId(Long roleId);

    @Transactional(timeout = 10)
    @Modifying
    @Query("update User u set u.usrName=?1 where u.usrId=?2")
    public int modifyNameById(String usrName,Long usrId);

    public List<User> findUsersByName(String usrName);

    @Query("select u from User u where u.usrRoleId=?1")
    public Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);

    Page<User> findAll(Specification<User> userSpecification, Pageable pageable);
}
